<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title></title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../../../lib/layui/css/layui.css" media="all">
  <link href="../../../lib/wangeditor/style.css" rel="stylesheet">
  <link href="../../../css/layout.css" rel="stylesheet">
  <link rel="stylesheet" href="../../../css/public.css" media="all">
  <style>
      body {
          background-color: #ffffff;
      }
  </style>
</head>
<body>
<div class="layui-form layuimini-form" id="myForm">
  <div class="layui-form-item">
    <label class="layui-form-label required">名称</label>
    <div class="layui-input-block">
      <input type="text" name="name" lay-verify="required" placeholder="请输入" value="" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label required" >地址</label>
    <div class="layui-input-block">
      <input type="text" name="href" lay-verify="required" placeholder="请输入" value="" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">排序</label>
    <div class="layui-input-block">
      <input type="number" name="qOrder" lay-verify="required" placeholder="请输入" value="" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">是否显示</label>
    <div class="layui-input-block">
      <input type="checkbox" name="showFlag" lay-skin="switch" lay-filter="topFlag" lay-text="是|否">
    </div>
  </div>
  <hr />
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">添加</button>
    </div>
  </div>
</div>

<script src="../../../lib/layui/layui.js" charset="utf-8"></script>
<script src="../../../lib/wangeditor/index.js"></script>
<script src="../../../api/common.js" charset="utf-8"></script>

<script>
    layui.use(['form', 'laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate;
        $ = layui.$;

        laydate.render({
            elem: '#createDate',
            type: 'datetime',
            fullPanel: true // 2.8+
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var obj = data.field
            if(obj.showFlag){
                obj.showFlag = true
            }else{
                obj.showFlag = false
            }
            console.log('obj', obj)
            $.ajax({
                type: 'POST',
                url: local + 'quick/insert',
                data: JSON.stringify(obj),
                dataType: "json",
                headers: {
                    'Authorization': `Bearer ${ localStorage.getItem("token") }`,
                },
                contentType: 'application/json;charset=UTF-8',
                success: function (res) {
                    console.log('data', res)
                    if (res.code === 200) {
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                        parent.layui.table.reload('currentTableId');
                        return false;
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert('操作失败！！！' + XMLHttpRequest.status + "|" + XMLHttpRequest.readyState + "|" + textStatus, {icon: 5});
                }
            });
        });
    });
</script>
</body>
</html>
